package bintree.leetcode;

import java.util.HashSet;
import java.util.Set;

public class Num3无重复最长字符串 {
    public int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<>();
        int ret = 0;
        int k=0;
        int m=0;
        int n = s.length();
        for (int i = 0; i < n; i++) {
            while (k<n&&!set.contains(s.charAt(m))){
                set.add(s.charAt(k));
                m++;
                k++;
            }
            ret = Math.max(ret,k);
            k=0;
            set.clear();
        }
        return ret;
    }
}
